package com.twq.collection.framework.seq

/**
 * Created by tangweiqun on 2017/12/10.
 */
object BuffersTest {
  def main(args: Array[String]): Unit = {
    //可变集合Buffer是Seq的一个子类
    //它不仅允许更新元素的更新，而且允许元素的插入和删除


    //ListBuffer 和 ArrayBuffer
    //5、可变集合Buffer的方法
    val buffer = scala.collection.mutable.Buffer(1, 2, 3, 1, 4) //Buffer的默认实现是ArrayBuffer
    //Additions
    buffer += 99
    buffer += (88, 100)
    buffer ++= Seq(1, 2, 3)
    101 +=: buffer
    Seq(1, 2, 3) ++=: buffer
    buffer.insert(3, 99999)
    buffer.insertAll(2, Seq(22, 33))

    //Removals
    buffer -= 99
    buffer.remove(3)
    buffer.remove(3, 4)
    buffer.trimStart(4)
    buffer.trimEnd(2)
    buffer.clear()

    //Cloning
    buffer.clone()
  }
}
